package com.vip.seata.at.business.tcc.impl;

import com.vip.seata.at.business.tcc.MallTccService;
import com.vip.seata.at.business.tcc.action.OrderAction;
import com.vip.seata.at.business.tcc.action.StockAction;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class MallTccServiceImpl implements MallTccService {

    @Resource
    OrderAction iOrderService;

    @Resource
    StockAction iStockService;

    @Override
    @GlobalTransactional(name = "TCC-创建订单")
    public void doBusiness(String orderId, String userId) throws Exception {
        log.info("开始全局事务，XID = " + RootContext.getXID());
        iOrderService.createOrder(null,userId,"200",1l);
        iStockService.minusStock(null,userId,"200",1l);
        //throw new RuntimeException("Runtime Fake Exception");
    }
}
